update result type
authorManuel Stühn <freebsd@justmail.de>
Tue, 16 Nov 2021 10:28:38 +0000 (11:28 +0100)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:57 +0000 (12:53 -0400)
rust-bindings/rust/src/repo.rs
rust-bindings/rust/tests/functions/mod.rs

index 486e087c9bd5aca97ebae2dd06e00f0833c8164e..f44a6c2d57ea5be5da6c0cb225cba72e2728e6dc 100644 (file)
@@ -24,28 +24,41 @@ unsafe extern "C" fn read_variant_table(
     set.insert(ObjectName::new_from_variant(value));
 }
 
-unsafe extern "C" fn read_variant_table_from_key(
+unsafe extern "C" fn read_variant_object_map(
     key: glib_sys::gpointer,
-    _value: glib_sys::gpointer,
+    value: glib_sys::gpointer,
     hash_set: glib_sys::gpointer,
 ) {
     let key: glib::Variant = from_glib_none(key as *const glib_sys::GVariant);
-    let set: &mut HashSet<ObjectName> = &mut *(hash_set as *mut HashSet<ObjectName>);
-    set.insert(ObjectName::new_from_variant(key));
+    let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
+    if let Some(insert) = value.get::<(bool, Vec<String>)>() {
+        let set: &mut HashMap<ObjectName, (bool, Vec<String>)> = &mut *(hash_set as *mut HashMap<ObjectName, (bool, Vec<String>)>);
+        set.insert(ObjectName::new_from_variant(key), insert);
+    }
 }
 
-unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable, from_key: bool) -> HashSet<ObjectName> {
+unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> HashSet<ObjectName> {
     let mut set = HashSet::new();
-    let read_variant_table_cb = if from_key { read_variant_table_from_key } else { read_variant_table };
     glib_sys::g_hash_table_foreach(
         ptr,
-        Some(read_variant_table_cb),
+        Some(read_variant_table),
         &mut set as *mut HashSet<ObjectName> as *mut _,
     );
     glib_sys::g_hash_table_unref(ptr);
     set
 }
 
+unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap<ObjectName, (bool, Vec<String>)> {
+    let mut set = HashMap::new();
+    glib_sys::g_hash_table_foreach(
+        ptr,
+        Some(read_variant_object_map),
+        &mut set as *mut HashMap<ObjectName, (bool, Vec<String>)> as *mut _,
+    );
+    glib_sys::g_hash_table_unref(ptr);
+    set
+}
+
 /// An open transaction in the repository.
 ///
 /// This will automatically invoke [`ostree::Repo::abort_transaction`] when the value is dropped.
@@ -127,7 +140,7 @@ impl Repo {
                 &mut error,
             );
             if error.is_null() {
-                Ok(from_glib_container_variant_set(hashtable, false))
+                Ok(from_glib_container_variant_set(hashtable))
             } else {
                 Err(from_glib_full(error))
             }
@@ -164,7 +177,7 @@ impl Repo {
         &self,
         flags: OstreeRepoListObjectsFlags,
         cancellable: Option<&P>,
-    ) -> Result<HashSet<ObjectName>, Error> {
+    ) -> Result<HashMap<ObjectName, (bool, Vec<String>)>, Error> {
         unsafe {
             let mut error = ptr::null_mut();
             let mut hashtable = ptr::null_mut();
@@ -178,7 +191,7 @@ impl Repo {
             );
 
             if error.is_null() {
-                Ok(from_glib_container_variant_set(hashtable, true))
+                Ok(from_glib_container_variant_map(hashtable))
             } else {
                 Err(from_glib_full(error))
             }
index cf15a3d99e53182751860c3a50ae7d31905d33c7..933bc897cd53c774e3101a13368962604b2f2707 100644 (file)
@@ -12,7 +12,7 @@ fn list_repo_objects() {
     let mut commit_cnt = 0;
 
     let objects = repo.repo.list_objects( ffi::OSTREE_REPO_LIST_OBJECTS_ALL, NONE_CANCELLABLE).expect("List Objects");
-    for object in objects {
+    for (object, _items) in objects {
         match object.object_type()  {
             ObjectType::DirTree => { dirtree_cnt += 1; },
             ObjectType::DirMeta => { dirmeta_cnt += 1; },